<?php
namespace Controller;

use Slim\Http\Request;
use Slim\Http\Response;
use Slim\Container;
use Intervention\Image\ImageManagerStatic as Image;


class UserApi extends Base
{

    public function __construct(Container $container)
    {
        parent::__construct($container);
        if ($this->getaccount() === false) {
            header("HTTP/1.1 400 Bad Request");
            echo 'no account error';
            exit;
        } else {
            $this->account = $this->getaccount();
        }
    }

    public function saveuser(Request $req, Response $res)
    {
        $validate = $this->guard->validateToken($req->getParam('tk_name'), $req->getParam('tk_value'));
        if ($validate === true) {
            $uid = $req->getParam('uid');
            $intergtal = $req->getParam('intergtal');
            if (empty($uid) || $this->checkfrom->regex('number', $uid) === false || $this->checkfrom->regex('number', $intergtal) === false) {
                return $res->withStatus(400)->write('data error');
                exit;
            } else {
                $count = $this->db->where(['uid' => $uid])->update('tcp_user', ['intergtal' => $intergtal, 'updatetime' => time()]);
                if (!empty($count)) {
                    return $res->withStatus(200)->write('保存成功');
                    exit;
                } else {
                    return $res->withStatus(400)->write('保存失败');
                    exit;
                }
            }
        }else{
            return $res->withStatus(400)->write('guard error');
            exit;
        }

    }



}